package com.kbbywyclient.presenter;

import android.content.Context;

import com.kbbywyclient.R;
import com.kbbywyclient.data.model.MineScoreModel;
import com.kbbywyclient.presenter.base.BasePresenter;
import com.kbbywyclient.service.ApiService;
import com.kbbywyclient.service.ApiServiceHelper;
import com.kbbywyclient.ui.contarct.MineScoreContract;
import com.kbbywyclient.util.HttpExcUtil;
import com.kbbywyclient.util.RsaJsonUtil;
import com.kbbywyclient.util.ToastUtil;

import javax.inject.Inject;

import rx.Observer;

/**
 * Created by cbb on 2017/4/21.
 */

public class MineScorePresenter extends BasePresenter implements MineScoreContract.Presenter{
    @Inject
    Context context;
    @Inject
    ApiService apiService;
    @Inject
    RsaJsonUtil rsaJsonUtil;

    private MineScoreContract.View view;

    @Inject
    public MineScorePresenter(MineScoreContract.View view){
        this.view=view;
    }

    @Override
    public void getMineScoreInfo(String salesId) {
        rsaJsonUtil.put("SalesID",salesId);

        view.showLoadingDialog(context.getString(R.string.loading));

        ApiServiceHelper.
                appointThreadNormal(apiService.getMineScoreInfo(rsaJsonUtil.getRsaParams())).
                subscribe(new Observer<MineScoreModel>() {
                    @Override
                    public void onCompleted() {
                        view.closeLoadingDialog();
                    }

                    @Override
                    public void onError(Throwable e) {
                        HttpExcUtil.printError(e);
                        view.closeLoadingDialog();
                    }

                    @Override
                    public void onNext(MineScoreModel mineScoreModel) {
                        if(mineScoreModel.getData()!=null){
                            view.onGetMineScoreInfoSuccess(mineScoreModel.getData());
                        }else{
                            ToastUtil.showShort(mineScoreModel.getMsg());
                            view.onGetMineScoreInfoFailure();
                        }
                    }
                });
    }
}
